package org.acompanhamento.pages.sprint;

import java.util.List;

import jmine.tec.di.annotation.Injected;
import jmine.tec.report.impl.table.ReportTableBuilder;
import jmine.tec.web.wicket.pages.form.CrudModelPage;
import jmine.tec.web.wicket.pages.form.FormType;

import org.acompanhamento.HelpMessages;
import org.acompanhamento.dao.SprintDAO;
import org.acompanhamento.domain.Sprint;
import org.apache.wicket.Page;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import bancosys.tec.exception.MessageCreator;
import bancosys.tec.persist.dao.BaseDAOFactory;
import bancosys.tec.security.annotation.Secure;
import bancosys.tec.security.authorization.UrlPermission;

@Secure(id = "GENERIC_TEAM_MEMBER_URL", permissionType = UrlPermission.class)
public class ListSprintPage extends CrudModelPage<SprintFilterVO, Sprint> {

	@Injected
	private SprintDAO sprintDAO;

	@Override
	public Page createNewPage() {
		return new EditSprintPage(new PageParameters(), this);
	}

	@Override
	public List<Sprint> search(BaseDAOFactory daoFactory) {
		return this.sprintDAO.findByStartDateEndDateTeam(this.getModel().getStartDate(),
				this.getModel().getEndDate(), this.getModel().getTeam());
	}

	@Override
	protected Page createFormPage(Sprint entity, FormType formType) {
		return new EditSprintPage(this, new PageParameters(), entity, formType);
	}

	@Override
	protected void addResultTableColumns(ReportTableBuilder<Sprint> table) {
		table.addDateColumn("start", "Data Início", "start");
		table.addDateColumn("end", "Data Final", "end");
		table.addStringColumn("team", "Equipe", "team");
		table.addStringColumn("workflow", "Fluxo de Trabalho", "workflow");
	}

	@Override
	protected SprintFilterVO createModel() {
		return new SprintFilterVO();
	}

	@Override
	protected MessageCreator getHelpTextCreator() {
		return HelpMessages.TEAMS;
	}

}
